import QtQuick 2.4

ScorePageForm {


    okImageButton.onClicked: {
        stackView.pop()
    }


    Component.onCompleted: {
        var   playerNumber  = Game.playerNumber
        //console.log("显示", playerNumber, "个选手的成绩")


        var maxItem  = 0;
        var minItem  = 0;
        var table  = [];
        for(var i = 0; i < playerNumber; i++){
            var item  = [];
            var playerId  = Game.playerIdAt(i)
            item.push(i+1)
            item.push(Game.correctNumberOf(playerId))
            item.push(Game.incorrectNumberOf(playerId))
            item.push(Game.scoreOf(playerId));

            table.push(item);
            console.log(item)
        }


        table.sort(sortCompare)

        console.log(table)

        var j  = 0;
        for( ; j < playerNumber; j++){
            switch(j){
            case 0:
                playerIdText_1  = table[0][0]
                rightNumberText_1  = table[0][1]
                errorNumberText_1  = table[0][2]
                scoreText_1  = table[0][3]
                break;
            case 1:
                playerIdText_2  = table[1][0]
                rightNumberText_2  = table[1][1]
                errorNumberText_2  = table[1][2]
                scoreText_2  = table[1][3]
                break;
            case 2:
                playerIdText_3  = table[2][0]
                rightNumberText_3  = table[2][1]
                errorNumberText_3  = table[2][2]
                scoreText_3  = table[2][3]
                break;
            }
        }


        for(; j < 3; j++){
            switch(j){
            case 0:
                playerIdText_1  = '';
                rightNumberText_1  = ''
                errorNumberText_1  = ''
                scoreText_1  = ''
                break;
            case 1:
                playerIdText_2  = '';
                rightNumberText_2  = ''
                errorNumberText_2  = ''
                scoreText_2  = ''
                break;
            case 2:
                playerIdText_3  = '';
                rightNumberText_3  = ''
                errorNumberText_3  = ''
                scoreText_3  = ''
                break;
            }
        }
    }

    function sortCompare(a,b){
        if(a[3] > b[3]){
            return -1
        }
        else if(a[3] === b[3]){
            return 0
        }
        else{
            return 1
        }
    }
}
